package com.jhl.seckill.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Date;


/**
 * RabbitMQ配置类
 */
@Configuration
public class RabbitMQTopicConfig {

    //    定义秒杀交换机和队列的名称
    static final String QUEUE = "seckillQueue";
    static final String EXCHANGE = "seckillExchange";
    static final Object EXPIRATION = new Date().getTime();

    //    队列实例
    @Bean
    public Queue queue() {
        return new Queue(QUEUE);
    }

    //    交换机实例
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange(EXCHANGE);
    }

    //    交换机绑定队列
    @Bean
    public Binding binding() {
        return BindingBuilder.bind(queue()).to(topicExchange()).with("seckill.#");
    }


}
